USE NutritionTracker
GO

IF EXISTS (SELECT * FROM sys.columns WHERE	[object_id] = object_id(N'MeasurementUnit') AND [name] = 'UIMaxLen')
	ALTER TABLE MeasurementUnit DROP COLUMN UIMaxLen
GO

ALTER TABLE		MeasurementUnit ADD UIMaxLen INT
GO

UPDATE		MeasurementUnit
SET		UIMaxLen =	CASE MeasurementUnitID
						WHEN 1 THEN 7
						WHEN 2 THEN 4
						WHEN 3 THEN 1
						WHEN 4 THEN 2
						WHEN 5 THEN 6
						WHEN 6 THEN 7
						WHEN 7 THEN 7
						WHEN 8 THEN 2
						WHEN 9 THEN 2
					END
WHERE		MeasurementUnitID IN (1,2,3,4,5,6,7,8,9)
GO

ALTER TABLE MeasurementUnit ALTER COLUMN UIMaxLen INT NOT NULL
GO